<?php

class Application_Model_CustomerOrderMapper extends App_Model_Mapper
{

    protected $dbTableName = 'Application_Model_DbTable_CustomerOrder';

    /*
     *  Calul le chiffre d'affaire pour une tranche donnée
     *  @param $begin int
     *  @param $end int
     *  @return $ca float
     */
    public function calculateTurnover($begin, $end)
    {
        $db = $this->getDbTable()->getAdapter();
        $table = $this->getDbTable()->getTable();
        $sql = "SELECT SUM(montant_total) as ca FROM $table WHERE date_envoi >= $begin AND date_envoi <= $end AND id_refusee = 0 AND num_facture != '' AND etat_envoyee = 1";
        //echo $sql;exit;
        $result = $db->fetchRow($sql);
        return $result['ca'];

    }

}

